var express = require('express');
var router = express.Router();
var formidable = require("formidable");
var fs = require("fs");

/*栏目管理*/
router.get('/upload', function (req, res, next) {
    res.render('upload/upload', {title: 'upload'});
});

router.post('/uploadfiles', function(req, res) {

    var form = new formidable.IncomingForm();   //创建上传表单
    form.encoding = 'utf-8';		//设置编辑
    form.uploadDir ='../temp';	 //设置上传目录
    //form.keepExtensions = true;	 //保留后缀
    form.maxFieldsSize = 2 * 1024 * 1024;   //文件大小

    form.parse(req, function(err, fields, files){
        var filepath=files.file.path;
        var filename=files.file.name;
        fs.rename(files.file.path, "../temp/"+filename);
    });
    // res.send({resultCode:20020000});
});


module.exports = router;